package com.example.testdemo.level3;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.testdemo.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by MrYan on 2018/8/7.
 * 三级联动 第一层适配器
 */

public class LevelThreeAdapter extends BaseQuickAdapter<String,BaseViewHolder> {
    private Context context;
    private List<String> company;
    private List<DataBean> dataBeanList;

    public LevelThreeAdapter(Context context,List<String> company) {
        super(R.layout.item_three_one);
        this.context = context;
        this.company = company;
        dataBeanList = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            DataBean bean = new DataBean();
            bean.setIndex(i);
            dataBeanList.add(bean);
        }
    }

    @Override
    protected void convert(BaseViewHolder helper, String item) {
        RecyclerView view = helper.getView(R.id.threeRv);
        view.setLayoutManager(new LinearLayoutManager(context));
        final LevelThreeTwoAdapter adapter = new LevelThreeTwoAdapter(context);
        view.setAdapter(adapter);
        View headlerView = LayoutInflater.from(context).inflate(R.layout.head_one,null);
        TextView headTitle = headlerView.findViewById(R.id.headTitle);
        headTitle.setText(item);
        adapter.addHeaderView(headTitle);

        adapter.getHeaderLayout().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (adapter.getData().size() > 0){
                    adapter.getData().clear();
                }else {
                    adapter.setNewData(dataBeanList);
                }
            }
        });
    }
}
